<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/broadcast', function () {
    try {
        event(new \App\Events\SayHelloEvent('Test message'));
        return 'Event dispatched';
    } catch (\Exception $e) {
        return 'Error: '. $e->getMessage();
    }
});

Route::get('/', function () {
    return redirect('/app');
});

Route::get('/app', function () {
    return view('app');
})->withoutMiddleware('web');



Route::get('/loan', function () {
    return view('loan');
})->withoutMiddleware('web');


Route::prefix('dashboard/v1')
    ->namespace('App\Http\Controllers\Api')
    ->group(function () {
        Route::get('/home', 'HomeController@index');
    });


Route::prefix('dashboard')
    ->namespace('App\Http\Controllers\Dashboard')
    ->middleware('auth:sanctum')
    ->withoutMiddleware('web')
    ->group(function () {
        Route::get('/', function () {
            return view('dashboard');
        })->withoutMiddleware('auth:sanctum');

        Route::get('/who', 'LoginController@whoami')->withoutMiddleware('auth:sanctum');
        Route::post('/login/send-sms', 'LoginController@sendSmsCode')->withoutMiddleware('auth:sanctum');
        Route::post('/login', 'LoginController@login')->withoutMiddleware('auth:sanctum');
        Route::post('/login/by-sms', 'LoginController@loginBySmsCode')->withoutMiddleware('auth:sanctum');
        Route::post('/logout', 'LoginController@logout');
        Route::post('/reset-password', 'LoginController@resetPassword');





        Route::get('/menus/tree', 'MenuController@tree');
        Route::get('/menus/org/{id}', 'MenuController@ids')->where('id', '[0-9]+');
        Route::post('/menus/org/{id}', 'MenuController@saveIds')->where('id', '[0-9]+');
        Route::get('/search/org', 'SearchController@org');
        Route::get('/search/org-city', 'SearchController@orgCity');
        Route::get('/search/user', 'SearchController@user');
        Route::get('/search/loan-class', 'SearchController@loanClass');




        Route::get('/org/tree', 'OrgController@tree');
        Route::get('/org/{id}', 'OrgController@detail')->where('id', '[0-9]+');
        Route::get('/org/{id}/user', 'OrgController@user')->where('id', '[0-9]+');
        Route::get('/org/{id}/manager', 'OrgController@manager')->where('id', '[0-9]+');
        Route::post('/org/{id}/manager', 'OrgController@setManager')->where('id', '[0-9]+');
        Route::post('/org/{id}', 'OrgController@edit')->where('id', '[0-9]+');
        Route::post('/org', 'OrgController@create');

        Route::get('/user', 'UserController@index');
        Route::get('/user/{id}', 'UserController@detail')->where('id', '[0-9]+');
        Route::get('/user/{id}/loan', 'UserController@loan')->where('id', '[0-9]+');
        Route::get('/user/{id}/money', 'UserController@money')->where('id', '[0-9]+');
        Route::get('/user/{id}/ticket', 'UserController@ticket')->where('id', '[0-9]+');
        Route::get('/user/{id}/kyc', 'UserController@kyc')->where('id', '[0-9]+');
        Route::post('/user/money/transfer', 'UserController@transferMoney');
        Route::post('/user/money/recharge', 'UserController@rechargeMoney')->middleware('manager:root');
        Route::post('/user/ticket/transfer', 'UserController@transferTicket');
        Route::post('/user/ticket/recharge', 'UserController@rechargeTicket')->middleware('manager:root');
        Route::post('/user/{id}/kyc', 'UserController@auditKyc')->middleware('manager:root');
        Route::post('/user/{id}', 'UserController@edit')->where('id', '[0-9]+');
        Route::post('/user', 'UserController@create');
        Route::get('/user/app', 'UserController@appUser');
        Route::post('/user/saveInviter', 'UserController@saveInviter');
        Route::get('/user/deposit', 'UserController@depositOrder');
        Route::get('/user/withdraw', 'UserController@moneyWithdraw');
        Route::post('/user/withdraw/status', 'UserController@saveWithdrawStatus')->middleware('manager:root');

        Route::get('/user/tag', 'UserController@tag');
        Route::post('/user/tag', 'UserController@saveTag');

        Route::get('/loan', 'LoanController@index');
        Route::get('/loan/{id}', 'LoanController@detail')->where('id', '[0-9]+');
        Route::post('/loan/{id}', 'LoanController@update')->where('id', '[0-9]+');
        Route::delete('/loan/delete/{id}', 'LoanController@delete')->where('id', '[0-9]+');



        Route::get('/loan/{id}/log', 'LoanController@log')->where('id', '[0-9]+');
        Route::post('/loan/{id}/log', 'LoanController@saveLog')->where('id', '[0-9]+');
        Route::get('/loan/template/{category}', 'ImportController@loanTemplate')->withoutMiddleware('auth:sanctum');
        Route::post('/loan/allocate', 'LoanController@allocate')->middleware('manager');
        Route::post('/loan/{id}/tag', 'LoanController@saveTag')->middleware('auth:sanctum');

        Route::post('/loan/{id}/refund', 'LoanController@saveRefund')->middleware('auth:sanctum');



        Route::get('/user/app', 'UserController@appUser');

        Route::get('/user/createUser', 'UserController@createUser')->middleware('auth:sanctum');



        Route::get('/loan/tag','LoanTagController@index');
        Route::post('/loan/tag', 'LoanTagController@create');
        Route::get('/loan/loan/{id}', 'LoanTagController@detail')->where('id', '[0-9]+');
        Route::delete('/loan/tag/{id}', 'LoanTagController@del')->where('id', '[0-9]+');
        Route::post('/loan/tag/{id}', 'LoanTagController@edit');


        Route::post('/import/upload', 'ImportController@upload')->middleware('manager:root');
        Route::post('/import/parse', 'ImportController@parse')->middleware('manager');
        Route::post('/import/save/{category}', 'ImportController@save')->middleware('manager:root');
        Route::post('/import/progress', 'ImportController@progress')->middleware('manager');

        Route::get('/app/setting/{key}', 'AppSettingController@get');
        Route::post('/app/setting/{key}', 'AppSettingController@save')->middleware('manager:root');

        Route::get('/app/setting_city/ticket', 'AppSettingController@getTicket');
        Route::post('/app/setting_city/ticket', 'AppSettingController@saveTicket')->withoutMiddleware('auth:sanctum');//->middleware('manager:root');



        Route::post('/app/setting_statistics/dataStatistics', 'AppSettingController@dataStatistics');



        Route::get('/app/loan_type/get', 'AppLoanTypeController@getLoanType');


        Route::post('/image/upload', 'ImageController@upload');

        Route::get('/app/qa','AppQaController@index');
        Route::post('/app/qa', 'AppQaController@create');
        Route::get('/app/qa/{id}', 'AppQaController@detail')->where('id', '[0-9]+');
        Route::delete('/app/qa/{id}', 'AppQaController@del')->where('id', '[0-9]+');
        Route::post('/app/qa/{id}', 'AppQaController@edit');

        Route::post('/chat/room/msg', 'ChatController@roomMsg')->middleware('auth:sanctum');
        Route::get('/chat/room/msg', 'ChatController@roomHistory')->middleware('auth:sanctum');
        Route::get('/chat/room/recent', 'ChatController@recentRoomList')->middleware('auth:sanctum');



        //网站
        //网站设置


//        Route::get('/org/tree', 'OrgController@tree');


        Route::get('/website/tree','WebOrgController@tree');
        Route::post('/website/tree', 'WebOrgController@save')->middleware('manager:root');

        Route::get('/website/setting/{key}','WebSettingController@get');
        Route::post('/website/setting/{key}', 'WebSettingController@save')->middleware('manager:root');
        //专员
        Route::get('/website/user','WebUserController@get');
        Route::post('/website/user', 'WebUserController@save')->middleware('manager:root');
        Route::post('website/user/{id}', 'WebUserController@edit')->where('id', '[0-9]+');
        Route::delete('/website/user/{id}', 'WebUserController@del')->where('id', '[0-9]+');
        //门店
        Route::get('/website/store','WebStoreController@get');
        Route::post('/website/store', 'WebStoreController@save')->middleware('manager:root');
        Route::post('website/store/{id}', 'WebStoreController@edit')->where('id', '[0-9]+');
        Route::delete('/website/store/{id}', 'WebStoreController@del')->where('id', '[0-9]+');
        //问题
        Route::get('/website/qa','WebQaController@get');
        Route::post('/website/qa,', 'WebQaController@save')->middleware('manager:root');
        Route::post('website/qa,/{id}', 'WebQaController@edit')->where('id', '[0-9]+');
        Route::delete('/website/qa,/{id}', 'WebQaController@del')->where('id', '[0-9]+');
        //资讯
        Route::get('/website/news','WebNewsController@get');
        Route::post('/website/news', 'WebNewsController@save')->middleware('manager:root');
        Route::post('website/news/{id}', 'WebNewsController@edit')->where('id', '[0-9]+');
        Route::delete('/website/news/{id}', 'WebNewsController@del')->where('id', '[0-9]+');
        //案例
        Route::get('/website/case','WebCaseController@get');
        Route::post('/website/case', 'WebCaseController@save')->middleware('manager:root');
        Route::post('website/case/{id}', 'WebCaseController@edit')->where('id', '[0-9]+');
        Route::delete('/website/case/{id}', 'WebCaseController@del')->where('id', '[0-9]+');
        //方案
        Route::get('/website/scheme','WebSchemeController@get');
        Route::post('/website/scheme', 'WebSchemeController@save')->middleware('manager:root');
        Route::post('website/scheme/{id}', 'WebSchemeController@edit')->where('id', '[0-9]+');
        Route::delete('/website/scheme/{id}', 'WebSchemeController@del')->where('id', '[0-9]+');





//        Route::get('/website/tree','WebsiteSettingController@tree');
//        Route::post('/website/setting', 'WebsiteSettingController@save')->middleware('manager:root');



});
